import groovy.mock.interceptor.MockFor
import net.yiny.scrummer.model.Card
import net.yiny.scrummer.ui.storyboard.CardControllerFactory
import static org.hamcrest.MatcherAssert.assertThat
import static org.hamcrest.Matchers.is

before_each "setup a factory", {
    factory = new CardControllerFactory()
}

scenario "the creation of a story controller and builder pair", {
    given "a valid factory and a valid card", {
        mockCard = new MockFor(Card)
        card = mockCard.proxyInstance()
    }
    when "the factory is asked to create a pair for the card", {
        controller = factory.createController(card)
    }
    then "the factory should return a controller", {
        controller.shouldNotBe null
    }
    and "the controller should have a builder set to it", {
        controller.builder.shouldNotBe null
    }
    and "it should have the given card set to it", {
        assertThat controller.card, is(card)
    }
}

scenario "throwing an exception if the story is null", {
    given "a valid factory and a null story", {
        card = null
    }
    when "the factory is asked to create a pair for the story", {
        wasThrown = true
        ensureThrows(IllegalArgumentException) {
            controller = factory.createController(card)
            wasThrown = false
        }
    }
    then "the factory should throw an IAE", {
        assertThat wasThrown, is(true)
    }
}